import { Controller, Get, Post, Body, Param, Query } from '@nestjs/common';
import { FriendsShipService } from './friends-ship.service';
import { CreateFriendsShipDto } from './dto/create-friends-ship.dto';

import { GetUserInfo, RequrieLogin } from 'src/cu-dec';

@Controller('friends-ship')
@RequrieLogin()
export class FriendsShipController {
  constructor(private readonly friendsShipService: FriendsShipService) {}

  // 请求添加好友
  @Post()
  create(
    @Body() createFriendsShipDto: CreateFriendsShipDto,
    @GetUserInfo('id') id: number,
  ) {
    return this.friendsShipService.create(createFriendsShipDto, +id);
  }

  @Get()
  findAll(@GetUserInfo('id') id: number) {
    return this.friendsShipService.findAll(+id);
  }

  // 获取请求列表
  @Get('getUserRequestList')
  getRequstList(@GetUserInfo('id') id: number) {
    return this.friendsShipService.getRequstList(+id);
  }

  // 同意好友请求
  @Get('agree/:id')
  agree(@Param('id') friendsId: number, @GetUserInfo('id') id: number) {
    return this.friendsShipService.agree(+friendsId, +id);
  }

  // 拒绝好友请求
  @Get('refuse/:id')
  refuse(@Param('id') friendsId: number, @GetUserInfo('id') id: number) {
    return this.friendsShipService.refuse(+friendsId, +id);
  }

  // 搜索好友
  @Get('search')
  search(@Query('username') username: string) {
    return this.friendsShipService.search(username);
  }
}
